﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using TeBigScreenWpf.Common;

namespace TeBigScreenWpf.Views
{
    internal class TeBannerGroup : ContentControl
    {
        private readonly double cornorRadiusX = 3;
        private readonly double cornorRadiusY = 3;

        private readonly double borderThickness = 1;

        private readonly Brush borderBackground = Themes.TeBannerGroup.borderBackground;
        private readonly Brush borderForeground = Themes.TeBannerGroup.borderForeground;
        private readonly Brush brushBackground = Themes.TeBannerGroup.brushBackground;

        public TeBannerGroup()
        {
        }

        private void DrawBackground(DrawingContext dc)
        {
            var bounds = new Rect(RenderSize);

            PathGeometry area = new PathGeometry();

            area.AddPolygon(new Point[]
            {
                new Point(bounds.Left, bounds.Top + cornorRadiusY),
                new Point(bounds.Left, bounds.Bottom - cornorRadiusY),

                new Point(bounds.Right, bounds.Bottom - cornorRadiusY),
                new Point(bounds.Right, bounds.Top + cornorRadiusY),
            });

            dc.DrawGeometry(brushBackground, null, area);

            //左边线
            {
                PathGeometry geo = new PathGeometry();

                geo.AddLines(new Point[]
                {
                     new Point(bounds.Left + cornorRadiusX, bounds.Top),
                     new Point(bounds.Left, bounds.Top + cornorRadiusY),
                     new Point(bounds.Left, bounds.Bottom - cornorRadiusY),
                     new Point(bounds.Left + cornorRadiusX, bounds.Bottom),
                });

                dc.DrawGeometry(null, new Pen(borderBackground, borderThickness * 2), geo);
                dc.DrawGeometry(null, new Pen(borderForeground, borderThickness), geo);
            }

            //右边线
            {
                PathGeometry geo = new PathGeometry();

                geo.AddLines(new Point[]
                {
                     new Point(bounds.Right - cornorRadiusX, bounds.Top),
                     new Point(bounds.Right, bounds.Top + cornorRadiusY),
                     new Point(bounds.Right, bounds.Bottom - cornorRadiusY),
                     new Point(bounds.Right - cornorRadiusX, bounds.Bottom),
                });

                dc.DrawGeometry(null, new Pen(borderBackground, borderThickness * 2), geo);
                dc.DrawGeometry(null, new Pen(borderForeground, borderThickness), geo);
            }
        }

        protected override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);

            DrawBackground(dc);
        }
    }
}